package com.dmzc.stage3.AQS;

public class Test1 {
    static int counter = 0;

    public static void main(String[] args) throws InterruptedException {
        Mutex mutex = new Mutex();
        Thread[] threads = new Thread[100];
        long currnent2;
        long current1;
        for (int j = 0; j < 100; j++) {
            threads[j] =
                    new Thread() {
                        @Override
                        public void run() {
                            try {
                                mutex.lock();
                                for (int i = 0; i < 100; i++)
                                    counter++;
                            } finally {
                                mutex.unlock();
                            }

                        }
                    };
        }
        current1 = System.currentTimeMillis();
        for (Thread thread : threads) thread.start();
        for (Thread thread : threads) thread.join();
        currnent2 = System.currentTimeMillis();
        System.out.println(currnent2 - current1);
        System.out.println(counter);
    }
}
